<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="(item,index) in list" :key="index">
                <p @click.slot="active = index">{{item.name}}</p>

                <ul v-show="active == index">
                    <input type="checkbox" v-model="item.checkAll" @click.slot="change(item.checkAll,index)"><span>全选</span>

                    <li v-for="(it,key) in item.children" :key="key">
                        <input type="checkbox" v-model="it.flag" @change="change1(index)">

                        <span>{{it.title}}</span>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</body>
</html>

<script>
    new Vue({
        el:'#app',
        data:{
            active:0,
            list:[
                {
                    name:'学员',
                    checkAll:false,
                    children:[
                        {
                            title:'第一组01',
                            flag:false,
                        },
                        {
                            title:'第一组02',
                            flag:false,
                        },
                        {
                            title:'第一组03',
                            flag:false,
                        },
                        {
                            title:'第一组04',
                            flag:false,
                        },
                    ]
                },
                {
                    name:'机构',
                    checkAll:false,
                    children:[
                        {
                            title:'机构01',
                            flag:false,
                        },
                        {
                            title:'机构02',
                            flag:false,
                        },
                        {
                            title:'机构03',
                            flag:false,
                        },
                        {
                            title:'机构04',
                            flag:false,
                        },
                    ]
                },
                {
                    name:'旅游',
                    checkAll:false,
                    children:[
                        {
                            title:'旅游01',
                            flag:false,
                        },
                        {
                            title:'旅游02',
                            flag:false,
                        },
                        {
                            title:'旅游03',
                            flag:false,
                        },
                        {
                            title:'旅游04',
                            flag:false,
                        },
                    ]
                },
                {
                    name:'爬山',
                    checkAll:false,
                    children:[
                        {
                            title:'爬山01',
                            flag:false,
                        },
                        {
                            title:'爬山02',
                            flag:false,
                        },
                        {
                            title:'爬山03',
                            flag:false,
                        },
                        {
                            title:'爬山04',
                            flag:false,
                        },
                    ]
                },
            ]
        },
        methods: {
            change(all,index) {
                this.list[index].children.forEach((item)=>(item.flag=!all))
            },
            change1(key) {
                let x = this.list[key].children.every((item)=>item.flag)
                console.log(x)
                this.list[key].checkAll=x
            }
        },
    })
</script>